package com.lg.wxq.ui;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import com.lg.wxq.config.SharedPreferencesConfig;
import com.lg.wxq.config.Strings;
import com.lg.wxq.utils.DebugUtils;
import com.weibo.net.DialogError;
import com.weibo.net.Token;
import com.weibo.net.Weibo;
import com.weibo.net.WeiboDialogListener;
import com.weibo.net.WeiboException;

public class StartActivity extends BaseActivity {
	private String expires_in;
	private long expiresTime;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start);

	}

	public void clickButton(View v) {

		Weibo weibo = Weibo.getInstance();
		weibo.authorize(this, new WeiboDialogListener() {

			public void onWeiboException(WeiboException e) {
				toast("Auth exception : " + e.getMessage());
			}

			public void onError(DialogError e) {
				toast("Auth error : " + e.getMessage());
			}

			public void onComplete(Bundle values) {
				Weibo weibo = Weibo.getInstance();
				Token token = weibo.getAccessToken();
				
				SharedPreferences sp = StartActivity.this.getSharedPreferences(SharedPreferencesConfig.SP_NAME, SharedPreferencesConfig.MODE_WR);
				sp.edit().putString(Strings.ACCESS_TOKEN, token.getToken()).putLong(Strings.EXPIRES_TIME, token.getExpiresIn()).commit();
				
				Intent intent=new Intent(StartActivity.this, MainActivity.class);
				startActivity(intent);
				finish();
			}
			public void onCancel() {
				toast("Auth cancel");
			}
		});
	}
}
